package top.wxdfun.sqlwr.config;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

@Aspect
@Component
@Slf4j
public class DataSourceAop {

    @Before("execution(* top.wxdfun.sqlwr.mapper.*.select*(..)) " +
            "|| execution(* top.wxdfun.sqlwr.mapper.*.count*(..)) " +
            "|| execution(* top.wxdfun.sqlwr.mapper.*.list*(..))")
    public void setReadDataSourceType() {
        DBContextHolder.read();
        log.info("dataSource切换到：Read");
    }

    @Before("execution(* top.wxdfun.sqlwr.mapper.*.insert*(..)) " +
            "|| execution(* top.wxdfun.sqlwr.mapper.*.update*(..)) " +
            "|| execution(* top.wxdfun.sqlwr.mapper.*.del*(..))")
    public void setWriteDataSourceType() {
        DBContextHolder.write();
        log.info("dataSource切换到：write");
    }
}
